package com.qtummatrix.controller;

import com.opensymphony.xwork2.ActionSupport;
import com.qtummatrix.service.BlacklistService;
import com.qtummatrix.utils.getExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller("upload")
public class uploadController extends ActionSupport {
    @Autowired
    private BlacklistService blacklistService;
    private getExcelUtil ExcelUtil;

    Map<String, Object> info = new HashMap<String, Object>();


    public Map<String, Object> getInfo() {
        return info;
    }


    public void setInfo(Map<String, Object> info) {
        this.info = info;
    }

    public String upload() {
        List<String[]> list = new ArrayList<String[]>();
        list = ExcelUtil.getExcel("C:/start/addBlacklist.xls");
        int count = 0;
        String UID = null;
        String name = null;
        String mark = null;
        String source = null;
        String type = null;
        if (list == null) {
            return INPUT;
        }
        for (int i = 0; i < list.size(); i++) {
            String[] str = (String[]) list.get(i);
            for (int j = 0; j < str.length; j++) {
                UID = str[0];
                name = str[1];
                mark = str[2];
                source = str[3];
                type = str[4];

            }
            count = blacklistService.addBlacklist(UID, name, mark, type, source);
        }
        if (count > 0) {
            info.put("message", "上传成功");
            return SUCCESS;
        } else {
            info.put("message", "上传失败");
            return INPUT;
        }

    }


}
